package com.example.fw;

import org.netbeans.jemmy.ClassReference;
import org.netbeans.jemmy.operators.JFrameOperator;

import java.lang.reflect.InvocationTargetException;
import java.util.Properties;

public class AppManager {
	
	private FoldersHelper foldersHelper;
    private JFrameOperator mainFrame;
    private MenuHelper menuHelper;

    public AppManager(Properties properties) {

	}
	
	public void stop() {
        getApplication().requestClose();
	}

	public FoldersHelper getFoldersHelper() {
		if (foldersHelper == null) {
			foldersHelper = new FoldersHelper(this);
		}
		return foldersHelper;
	}

    public MenuHelper getMenuHelper() {
        if (menuHelper == null) {
            menuHelper = new MenuHelper(this);
        }
        return menuHelper;
    }

    public JFrameOperator getApplication() {
        if (mainFrame == null) {
            try {
                new ClassReference("addressbook.AddressBookFrame").startApplication();
                mainFrame = new JFrameOperator("jAddressBook");
            } catch ( Exception e) {
                e.printStackTrace();
                return null;
            }
        }
        return mainFrame;
    }
}
